package com.longge;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @创建人 xinglongge
 * @创建时间 2021/10/14
 * @描述
 */
public class FindWords {

    public static HashSet<Character> setOne = new HashSet<>();
    public static HashSet<Character> setTwo = new HashSet<>();
    public static HashSet<Character> setThree = new HashSet<>();

    static {
        String one = "qwertyuiop";
        String two = "asdfghjkl";
        String three = "zxcvbnm";
        for (char c : one.toCharArray()) {
            setOne.add(c);
        }
        for (char c : two.toCharArray()) {
            setTwo.add(c);
        }
        for (char c : three.toCharArray()) {
            setThree.add(c);
        }
    }

    public String[] findWords(String[] words) {

        List<String> res = new ArrayList<>();
        for (String word : words) {
            String lowerWord = word.toLowerCase();
            int oneCount = 0, twoCount = 0, threeCount = 0;
            for (char c : lowerWord.toCharArray()) {
                if (setOne.contains(c)) oneCount++;
                if (setTwo.contains(c)) twoCount++;
                if (setThree.contains(c)) threeCount++;
            }
            int length = word.length();
            if (oneCount == length || twoCount == length || threeCount == length) res.add(word);
        }
        return res.toArray(new String[]{});

    }

    public static void main(String[] args) {
        new FindWords().findWords(new String[]{"Hello", "Alaska", "Dad", "Peace"});
    }

}
